package com.cashoutgaming.client.widgets.recent_matches;

import java.util.ArrayList;
import java.util.List;
import com.cashoutgaming.client.common.SessionManager;
import com.cashoutgaming.shared.game.GameType;
import com.cashoutgaming.shared.match.MatchDTO;
import com.cashoutgaming.shared.match.MatchFilterDTO;
import com.cashoutgaming.shared.match.MatchPagingLoadResult;
import com.cashoutgaming.shared.team.TeamLightDTO;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.HasUiHandlers;
import com.gwtplatform.mvp.client.PresenterWidget;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.proxy.PlaceManager;

/**
 * This is the desktop mode presenter for the admin tool. This presenter will
 * contain all buisness logic to drive the admin tool. This presenter will
 * likely invoke other presenters / presenter widgets; e.g. customer
 * create/modify dialog
 */
public class RecentMatchesPresenter extends PresenterWidget<RecentMatchesPresenter.MyView> implements RecentMatchesUiHandlers {

	private final PlaceManager placeManager;
	private final SessionManager session;

	public interface MyView extends View, HasUiHandlers<RecentMatchesUiHandlers> {

		public void loadData(MatchPagingLoadResult result);

		public void load();

		public void mask();

		public void unmask();
	}

	@Inject
	RecentMatchesPresenter(EventBus eventBus, MyView view, PlaceManager placeManager, SessionManager currentSession) {
		super(eventBus, view);
		this.placeManager = placeManager;
		this.session = currentSession;
		view.setUiHandlers(this);
	}

	@Override
	public void onReveal() {
		super.onReveal();
		getView().load();
	}

	public void load() {
		getView().load();
	}

	@Override
	public void getMatches(MatchFilterDTO filter) {
		loadFakeMatchData();// TODO REMOVE WHEN WIRED UP
	}

	public void loadFakeMatchData() {
		MatchDTO match1 = new MatchDTO();
		match1.setId(1L);
		match1.setGameType(GameType.COD_BO2);
		match1.setTeamOne(new TeamLightDTO(1L, "LoKo Alpha"));
		match1.setTeamOneWins(2);
		match1.setTeamTwo(new TeamLightDTO(2L, "LoKo Bravo"));
		match1.setTeamTwoWins(1);
		match1.setWager("25.00");

		MatchDTO match2 = new MatchDTO();
		match2.setId(2L);
		match2.setGameType(GameType.COD_BO2);
		match2.setTeamOne(new TeamLightDTO(1L, "LoKo Alpha"));
		match2.setTeamOneWins(2);
		match2.setTeamTwo(new TeamLightDTO(3L, "XBL Gaming"));
		match2.setTeamTwoWins(0);
		match2.setWager("5.00");

		MatchDTO match3 = new MatchDTO();
		match3.setId(3L);
		match3.setGameType(GameType.COD_BO2);
		match3.setTeamOne(new TeamLightDTO(1L, "Variant Stars"));
		match3.setTeamOneWins(2);
		match3.setTeamTwo(new TeamLightDTO(1L, "LoKo Bravo"));
		match3.setTeamTwoWins(0);
		match3.setWager("15.00");

		MatchDTO match4 = new MatchDTO();
		match4.setId(4L);
		match4.setGameType(GameType.COD_BO2);
		match4.setTeamOne(new TeamLightDTO(1L, "XBL Gaming"));
		match4.setTeamOneWins(0);
		match4.setTeamTwo(new TeamLightDTO(1L, "LoKo Bravo"));
		match4.setTeamTwoWins(2);
		match4.setWager("50.00");

		MatchDTO match5 = new MatchDTO();
		match5.setId(5L);
		match5.setGameType(GameType.COD_BO2);
		match5.setTeamOne(new TeamLightDTO(1L, "Flannels OFF"));
		match5.setTeamOneWins(2);
		match5.setTeamTwo(new TeamLightDTO(1L, "Sluggers iR"));
		match5.setTeamTwoWins(1);
		match5.setWager("100.00");

		List<MatchDTO> matches = new ArrayList<MatchDTO>();
		matches.add(match1);
		matches.add(match2);
		matches.add(match3);
		matches.add(match4);
		matches.add(match5);

		MatchPagingLoadResult plr = new MatchPagingLoadResult();
		plr.setOffset(0);
		plr.setTotalLength(5);
		plr.setData(matches);
		getView().loadData(plr);
	}
}
